<?php
 /*
 * 1626cms 文章保存頁面
 * ============================================================================
 * 版權所有: 1626網絡，并保留所有權利。
 * 網站地址: http://www.1626.com；
 * ----------------------------------------------------------------------------
 * 這不是一個自由軟件！您只能在不用于商業目的的前提下對程序代碼進行修改和
 * 使用；不允許對程序代碼以任何形式任何目的的再發布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once('../data/config.php');
require_once('./include/admin_common.inc.php');
require_once(ADMIN_ROOT_PATH.'include/upload_img.php');
require_once(ADMIN_ROOT_PATH.'include/admin_article_fun.php');
$act = !empty($_GET['act']) ? trim($_GET['act']) : '';
//保存添加
if($act == 'addsave'){
$title=$_POST['title'];
$type_id=$_POST['type_id'];
$content=$_POST['content'];
$tit_color=$_POST['tit_color'];
$tit_b=$_POST['tit_b'];
$Small_img=$_POST['Small_img'];
$author=$_POST['author'];
$source=$_POST['source'];
$focos=$_POST['focos'];
$is_display=$_POST['is_display'];
$is_url=$_POST['is_url'];
$seo_keywords=$_POST['seo_keywords'];
$seo_description=$_POST['seo_description'];
$article_order=$_POST['article_order'];
//----------------------
if($_FILES['Small_img']['name'])
{
$Small_img=_asUpFiles($upfiles_dir, "Small_img", 1024*2, 'jpg/gif/png',true);
$makefile=$upfiles_dir.$Small_img;
makethumb($makefile,$thumb_dir,$thumbwidth,$thumbheight);
}
if($title == ''){
showmsg('文章標題不能為空',1);
}
if($type_id == ''){
showmsg('文章所屬分類不能為空',1);
}
if($content == ''){
showmsg('文章內容不能為空',1);
}
$addtime=$timestamp;
$ParentID=get_article_ParentID($type_id);
$sql = "INSERT INTO ".table('article')." (type_id,ParentID,title,content,tit_color,tit_b,Small_img,author,source,focos,is_display,is_url,seo_keywords,seo_description,addtime,article_order) VALUES  ('$type_id','$ParentID','$title','$content','$tit_color','$tit_b','$Small_img','$author','$source','$focos','$is_display','$is_url','$seo_keywords','$seo_description','$addtime','$article_order')";
$db->query($sql);
$link[0]['text'] = "繼續添加文章";
$link[0]['href'] = 'admin_article.php?act=2&ty_id='.$type_id;
$link[1]['text'] = "返回文章列表";
$link[1]['href'] = 'admin_article.php?act=1';
showmsg("添加成功！",2,$link);
}
//保存修改--------------------------------
if($act == 'editsave')
{
$id=$_POST['id'];
$title=$_POST['title'];
$type_id=$_POST['type_id'];
$content=$_POST['content'];
$tit_color=$_POST['tit_color'];
$tit_b=$_POST['tit_b'];
$Small_img=$_POST['Small_img'];
$author=$_POST['author'];
$source=$_POST['source'];
$focos=$_POST['focos'];
$is_display=$_POST['is_display'];
$is_url=$_POST['is_url'];
$seo_keywords=$_POST['seo_keywords'];
$seo_description=$_POST['seo_description'];
$article_order=$_POST['article_order'];
//----------------------
if($_FILES['Small_img']['name'])
{
$Small_img=_asUpFiles($upfiles_dir, "Small_img", 1024*2, 'jpg/gif/png',true);
$makefile=$upfiles_dir.$Small_img;
makethumb($makefile,$thumb_dir,$thumbwidth,$thumbheight);
}
if($title == ''){
showmsg('文章標題不能為空',1);
}
if($type_id == ''){
showmsg('文章所屬分類不能為空',1);
}
if($content == ''){
showmsg('文章內容不能為空',1);
}
$addtime=$timestamp;
$ParentID=get_article_ParentID($type_id);
if($Small_img<>"")
{
$sql="update ".table('article')." set type_id='".$type_id."',ParentID='".$ParentID."',title='".$title."',content='".$content."',tit_color='".$tit_color."',tit_b='".$tit_b."' ,Small_img='".$Small_img."',author='".$author."',source='".$source."',focos='".$focos."',is_display='".$is_display."',is_url='".$is_url."',seo_keywords='".$seo_keywords."',seo_description='".$seo_description."',article_order='".$article_order."' where id=".$id;
}
else
{
$sql="update ".table('article')." set type_id='".$type_id."',ParentID='".$ParentID."',title='".$title."',content='".$content."',tit_color='".$tit_color."',tit_b='".$tit_b."',author='".$author."',source='".$source."',focos='".$focos."',is_display='".$is_display."',is_url='".$is_url."',seo_keywords='".$seo_keywords."',seo_description='".$seo_description."',article_order='".$article_order."' where id=".$id;
}
$db->query($sql);
$link[0]['text'] = "返回文章列表";
$link[0]['href'] = 'admin_article.php?act=1';
$link[1]['text'] = "查看已修改文章";
$link[1]['href'] = "admin_article.php?act=article_edit&id=".$id;
showmsg("修改成功！",2,$link);
}
//保存修改分類（所有）
if($act == 'category_all_save')
{
$y_id=$_POST['y_id'];
$categoryname=$_POST['categoryname'];
$category_order=$_POST['category_order'];
$y_num=count($y_id);
for($i=0;$i<$y_num;$i++)
{
$sql="update ".table('article_category')." set categoryname='".$categoryname[$i]."',category_order='".$category_order[$i]."'  where id='$y_id[$i]'";
$db->query($sql);
}
showmsg("成功修改！",2);
}
//保存修改分類（單個）
if($act == 'edit_category_save')
{
$id=$_POST['id'];
$ParentID=$_POST['ParentID'];
$categoryname=$_POST['categoryname'];
$category_order=$_POST['category_order'];
$title=$_POST['title'];
$description=$_POST['description'];
$keywords=$_POST['keywords'];
$sql="update ".table('article_category')." set ParentID='".$ParentID."', categoryname='".$categoryname."',category_order='".$category_order."',title='".$title."' ,description='".$description."',keywords='".$keywords."' where id='$id'";
$db->query($sql);
$link[0]['text'] = "查看修改結果";
$link[0]['href'] = 'admin_article.php?act=edit_category&y_id='.$id;
$link[1]['text'] = "返回分類管理";
$link[1]['href'] = 'admin_article.php?act=4';
showmsg("成功修改！",2,$link);
}
//保存增加分類
if($act == 'add_category_save')
{
!empty($_POST['categoryname']) ? ($categoryname=trim($_POST['categoryname'])) : showmsg("請填寫名稱",1);
$ParentID=!empty($_POST['ParentID']) ? trim($_POST['ParentID']) :'0';
$category_order=!empty($_POST['category_order']) ? trim($_POST['category_order']):'0';
$title=$_POST['title'];
$description=$_POST['description'];
$keywords=$_POST['keywords'];
$sql = "INSERT INTO ".table('article_category')." (ParentID,categoryname,category_order,title,description,keywords) VALUES  ('$ParentID','$categoryname','$category_order','$title','$description','$keywords')";
$db->query($sql);
$link[0]['text'] = "返回分類管理";
$link[0]['href'] = 'admin_article.php?act=4';
$link[1]['text'] = "繼續添加分類";
$link[1]['href'] = "admin_article.php?act=category_add&ParentID=".$ParentID;
showmsg("添加成功！",2,$link);
}
//保存修改屬性分類（所有）
if($act == 'property_all_save')
{
$y_id=$_POST['y_id'];
$categoryname=$_POST['categoryname'];
$y_num=count($y_id);
for($i=0;$i<$y_num;$i++)
{
$sql="update ".table('article_property')." set categoryname='".$categoryname[$i]."' where id='$y_id[$i]'";
$db->query($sql);
}
showmsg("成功修改！",2);
}
//保存增加屬性分類
if($act == 'add_property_save')
{
!empty($_POST['categoryname']) ? ($categoryname=trim($_POST['categoryname'])) : showmsg("請填寫名稱",1);
$sql = "INSERT INTO ".table('article_property ')." (categoryname) VALUES  ('$categoryname')";
$db->query($sql);
$link[0]['text'] = "返回屬性管理頁面";
$link[0]['href'] = 'admin_article.php?act=3';
$link[1]['text'] = "繼續添加屬性";
$link[1]['href'] = "admin_article.php?act=property_add";
showmsg("添加成功！",2,$link);
}
//刪除文章或修改文章分類（批量/單個）
if($act == 'migrate_article')
{
$y_id=$_REQUEST['y_id'];
$type_id=$_POST['type_id'];
$migrate=$_POST['migrate'];
$del_Submit=$_POST['del_Submit'];
if ($y_id=="")
{
showmsg("請選擇項目！",1);
exit;
}
if ($del_Submit<>"" and is_array($y_id))
{
$y_num=count($y_id);
for($i=0;$i<$y_num;$i++)
{
$sql_img="select * from ".table('article')." where id=".$y_id[$i];
$y_img=$db->getone($sql_img);
@unlink($upfiles_dir."/".$y_img['Small_img']);
@unlink($thumb_dir.$y_img['Small_img']);
$db->query("Delete from  ".table('article')." where id=".$y_id[$i]);
}
showmsg("刪除成功！",2);
}
if (!is_array($y_id))
{
$sql_img="select * from ".table('article')." where id=".$y_id;
$y_img=$db->getone($sql_img);
@unlink($upfiles_dir."/".$y_img['Small_img']);
@unlink($thumb_dir.$y_img['Small_img']);
$db->query("Delete from  ".table('article')." where id=".$y_id);
showmsg("刪除成功！",2);
}
//批量修改文章分類
if ($migrate<>"" && is_array($y_id))
{
!empty($type_id) ? $ParentID=get_article_ParentID($type_id) :showmsg("請選擇目標分類！",1);
$y_num=count($y_id);
for($i=0;$i<$y_num;$i++)
{
$db->query("update ".table('article')."  set type_id='".$type_id."',ParentID='".$ParentID."' where id=".$y_id[$i]);
}
showmsg("轉移成功！",2);
}
}
//刪除縮略圖（單個）
if($act == 'del_img')
{
$id=$_GET['id'];
$img=$_GET['img'];
$sql="update ".table('article')." set Small_img='' where id=".$id;
$db->query($sql);
@unlink($upfiles_dir."/".$img);
@unlink($thumb_dir.$img);
showmsg("刪除縮略圖成功！",2);
}
//刪除屬性分類（單個）
if($act == 'del_property')
{
$y_id=$_GET['y_id'];
$db->query("Delete from  ".table('article_property')." where id=".$y_id." AND admin_set<>'1'");
showmsg("刪除成功！",2);
}
//刪除分類（單個）
if($act == 'del_category')
{
if (intval($y_id)!=$y_id)return false;
$y_id=intval($_GET['y_id']);
get_article_Parent_list($y_id)? showmsg("請先刪除此分類下的小類！",1):'';
$sql = "select * from ".table('article')." where type_id=".$y_id;
$category_one=$db->getone($sql);
if ($category_one)showmsg("請先刪除此分類下的文章！",1);
$db->query("Delete from  ".table('article_category')." where id=".$y_id." AND admin_set<>'1'");
showmsg("刪除成功！",2);
}
?>
